package think.thread.c02;

import java.util.concurrent.TimeUnit;

class ReBegina extends Thread {

	private static volatile boolean canceled = false;

	public void cancel() {
		canceled = true;
	}

	public void begin() {
		canceled = false;
	}

	public boolean isCancel() {
		return canceled;
	}

	public void run() {
		while (!isCancel()) {
			System.out.println("o");
		}
	}
}

public class ThreadSleep {

	public static void main(String[] args) throws Exception {
		ReBegina reBegina = new ReBegina();
		reBegina.start();

		TimeUnit.SECONDS.sleep(1);
		reBegina.cancel();
		System.out.println("stop");

		TimeUnit.SECONDS.sleep(1);
		reBegina.begin();
		System.out.println("begin");
	}
	
	

}
